<template>
  <div class="settings-container">
    <h2>系统设置</h2>
    <div class="settings-content">
      <div class="setting-section">
        <h3>基本设置</h3>
        <div class="setting-item">
          <label for="site-name">网站名称</label>
          <input type="text" id="site-name" v-model="siteName">
        </div>
        <div class="setting-item">
          <label for="theme">主题设置</label>
          <select id="theme" v-model="theme">
            <option value="light">浅色主题</option>
            <option value="dark">深色主题</option>
          </select>
        </div>
        <div class="setting-item">
          <label for="language">语言偏好</label>
          <select id="language" v-model="language">
            <option value="zh-CN">简体中文</option>
            <option value="en-US">English</option>
          </select>
        </div>
      </div>
      <div class="setting-section">
        <h3>安全设置</h3>
        <div class="setting-item">
          <label>双重认证</label>
          <div class="toggle-switch">
            <input type="checkbox" id="two-factor" v-model="twoFactorEnabled">
            <label for="two-factor" class="toggle"></label>
          </div>
        </div>
        <div class="setting-item">
          <label for="password-change">修改密码</label>
          <button class="btn-primary">修改密码</button>
        </div>
      </div>
      <div class="setting-section">
        <h3>通知设置</h3>
        <div class="setting-item">
          <label>邮件通知</label>
          <div class="toggle-switch">
            <input type="checkbox" id="email-notify" v-model="emailNotificationsEnabled">
            <label for="email-notify" class="toggle"></label>
          </div>
        </div>
        <div class="setting-item">
          <label>系统通知</label>
          <div class="toggle-switch">
            <input type="checkbox" id="system-notify" v-model="systemNotificationsEnabled">
            <label for="system-notify" class="toggle"></label>
          </div>
        </div>
      </div>
    </div>
    <div class="actions">
      <button class="btn-primary" @click="saveSettings">保存设置</button>
      <button class="btn-secondary" @click="resetSettings">重置</button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

// 设置状态
const siteName = ref('Vue 导航组件示例');
const theme = ref('light');
const language = ref('zh-CN');
const twoFactorEnabled = ref(false);
const emailNotificationsEnabled = ref(true);
const systemNotificationsEnabled = ref(true);

// 保存设置
const saveSettings = () => {
  console.log('保存设置:', {
    siteName: siteName.value,
    theme: theme.value,
    language: language.value,
    twoFactorEnabled: twoFactorEnabled.value,
    emailNotificationsEnabled: emailNotificationsEnabled.value,
    systemNotificationsEnabled: systemNotificationsEnabled.value
  });
  alert('设置已保存！');
};

// 重置设置
const resetSettings = () => {
  siteName.value = 'Vue 导航组件示例';
  theme.value = 'light';
  language.value = 'zh-CN';
  twoFactorEnabled.value = false;
  emailNotificationsEnabled.value = true;
  systemNotificationsEnabled.value = true;
};
</script>

<style scoped>
.settings-container {
  padding: 40px;
  max-width: 1000px;
  margin: 0 auto;
}

h2 {
  font-size: 28px;
  color: #333;
  margin-bottom: 32px;
}

.settings-content {
  display: grid;
  grid-template-columns: 1fr;
  gap: 32px;
  margin-bottom: 40px;
}

.setting-section {
  background-color: white;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

h3 {
  font-size: 20px;
  color: #333;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0f0f0;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid #f5f5f5;
}

.setting-item:last-child {
  border-bottom: none;
}

.setting-item label {
  font-size: 16px;
  color: #333;
}

.setting-item input[type="text"],
.setting-item select {
  padding: 8px 12px;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  font-size: 14px;
  min-width: 200px;
}

/* 开关样式 */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 28px;
}

.toggle:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .toggle {
  background-color: #1890ff;
}

input:checked + .toggle:before {
  transform: translateX(24px);
}

/* 按钮样式 */
.actions {
  display: flex;
  gap: 16px;
}

.btn-primary,
.btn-secondary {
  padding: 10px 24px;
  border-radius: 4px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s;
}

.btn-primary {
  background-color: #1890ff;
  color: white;
  border: none;
}

.btn-primary:hover {
  background-color: #40a9ff;
}

.btn-secondary {
  background-color: white;
  color: #666;
  border: 1px solid #d9d9d9;
}

.btn-secondary:hover {
  border-color: #1890ff;
  color: #1890ff;
}

@media (max-width: 768px) {
  .settings-container {
    padding: 20px;
  }
  
  .setting-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .setting-item input[type="text"],
  .setting-item select {
    width: 100%;
    min-width: unset;
  }
}
</style>